home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr30 / hercb21.zip / HERCPIXL.C < prev    next >
Text File  |  1993-05-03  |  5KB  |  242 lines

  1. /*
  2.  *    HERCPIXL.C
  3.  *    Dave Tutelman  -  last modified 8/88
  4.  *
  5.  *    This is a set of basic graphic routines for the Hercules
  6.  *    Board (or at least the SuperComputer version of it; I assume
  7.  *     that they work with the real thing).
  8.  *        alfa ()        puts us in alphanumeric mode.
  9.  *        grafix (mode)    puts us in some graphics mode.
  10.  *        pixel (x,y,val)    puts a pixel at <x,y>. Bright dot if
  11.  *                val=1, dark dot if val=0.
  12.  *         dchar (x,y,c)    puts character "c" at <x,y>. Note that
  13.  *                character raster is 90 x 29.
  14.  *        nchar (x,y,c,n)    puts "n"copies of "c" at <x,y>.
  15.  *        setattr (attr)    sets the attribute for any characters
  16.  *                written by dchar().
  17.  *        hputc (c)    puts character "c" at current cursor,
  18.  *                using BIOS TTY write function.
  19.  *        hputs (s)    puts string "s" starting at current cursor.
  20.  *        swpage (page)    switches to a different page.
  21.  *        scroll (top,left,bottom,right,size,attr)
  22.  *                scroll an area of the screen.
  23.  *            waitkey ()    just waits till a key is pressed.
  24.  *
  25.  *    Actually, the routines should work with any board, since the
  26.  *    BIOS calls are used throughout.  It's Hercules-specific only
  27.  *    because I've defined the graphics and alpha modes for my
  28.  *    Hercules BIOS.
  29.  *
  30.  *    Making BIOS calls from C must be done in a compiler-dependent
  31.  *    way.  The code below shows styles for three different compilers:
  32.  *       -    Microsoft C uses int86() and the union REGS variables.
  33.  *       -    Turbo C uses int86() and the union REGS, but also supports
  34.  *            geninterrupt() and _AX, _BX, ...
  35.  *       -    DeSmet C uses _doint() and _rax, _rbx, ...
  36.  *    This file compiles under Turbo C, and provides enough examples
  37.  *    so that you should be able to port it to Microsoft or DeSmet.
  38.  */
  39.  
  40. #define TURBO
  41.    /* Define the correspondence between DeSmet and Turbo calls */
  42. #ifdef TURBO
  43. #    include    <dos.h>
  44. #    define    _doint    geninterrupt
  45. #    define    _rax    _AX
  46. #    define    _rbx    _BX
  47. #    define    _rcx    _CX
  48. #    define    _rdx    _DX
  49. #endif
  50.  
  51. #define VIDI    0x10        /* video interrupt, normally 10H  */
  52. #define    KBD    0x16        /* keyboard interrupt */
  53. #define ALFA_MODE    7    /* monochrome alpha mode */
  54.  
  55. int    page = 0;
  56. unsigned char current_attr = 07;
  57. #ifndef TURBO
  58.     extern unsigned _rax,_rbx,_rcx,_rdx;
  59. #endif
  60.  
  61. /*
  62.  * This puts us back in alphanumeric mode
  63.  */
  64.  
  65. alfa ()
  66. {
  67.     _rax = ALFA_MODE;    /* mono 80-col mode */
  68.     _doint ( VIDI );    /* set mode */
  69. }
  70.  
  71. /*
  72.  *    This one switches us to a graphics mode
  73.  */
  74.  
  75. grafix (mode)
  76.     int mode;
  77. {
  78.  
  79.     _rax = mode;            /* herc grafix mode */
  80.     _doint ( VIDI );    /* set mode */
  81.  
  82. }
  83.  
  84. /*
  85.  *   This writes a pixel at (x,y), where (0,0) is the upper-left
  86.  *   corner of the screen.  If val = 0 then the pixel is erased.
  87.  */
  88.  
  89. pixel (x, y, val)
  90.     int x, y, val;
  91. {
  92.  
  93.     _rax = 0x0C00 + val;    /* function 12      */    
  94.     _rcx = x;
  95.     _rdx = y;
  96.     _doint ( VIDI );    /* set mode */
  97.  
  98. }
  99.  
  100.  
  101. /*
  102.  *    dchar (x,y,c)    puts character "c" at <x,y>. Note that
  103.  *            character raster is 90 x 25.
  104.  */
  105.  
  106. setattr (color)
  107.   unsigned char color;
  108. {
  109.     current_attr = color;
  110. }
  111.  
  112. dchar (x,y,c)
  113.     int x,y;
  114.     char c;
  115. {
  116.  
  117. #ifdef TURBO
  118.     union REGS rr;
  119.  
  120.     rr.h.ah = 2;        /* move cursor function */
  121.     rr.h.dh = y;
  122.     rr.h.dl = x;
  123.     rr.h.bh = page;
  124.     int86 (VIDI, &rr, &rr);
  125.  
  126.     rr.h.ah = 9;        /* write character function */
  127.     rr.h.al = c;
  128.     rr.x.cx = 1;
  129.     rr.h.bh = page;
  130.     rr.h.bl = current_attr;
  131.     int86 (VIDI, &rr, &rr);
  132. #else
  133.     _rax = 2*256;        /* AH=Fn#2 */
  134.     _rdx = 256*y + x;        /* DH=row, DX=col */
  135.     _rbx = page * 256;        /* BH=page  */
  136.     _doint (VIDI);        /* set cursor */
  137.  
  138.     _rax = 0x900 + c;        /* AH=Fn#9, AL=char */
  139.     _rcx = 1;            /* CX=count */
  140.     _rbx = page*256 + current_attr;    /* BH=page, BL=attr */
  141.     _doint (VIDI);        /* write character */
  142. #endif
  143. }
  144.  
  145. nchar (x,y,c,n)
  146.     int x,y, n;
  147.     char c;
  148. {
  149.  
  150. #ifdef TURBO
  151.     union REGS rr;
  152.  
  153.     rr.h.ah = 2;        /* move cursor function */
  154.     rr.h.dh = y;
  155.     rr.h.dl = x;
  156.     rr.h.bh = page;
  157.     int86 (VIDI, &rr, &rr);
  158.  
  159.     rr.h.ah = 9;        /* write character function */
  160.     rr.h.al = c;
  161.     rr.x.cx = n;
  162.     rr.h.bh = page;
  163.     rr.h.bl = current_attr;
  164.     int86 (VIDI, &rr, &rr);
  165. #else
  166.     _rax = 2*256;        /* AH=Fn#2 */
  167.     _rdx = 256*y + x;        /* DH=row, DX=col */
  168.     _rbx = page * 256;        /* BH=page  */
  169.     _doint (VIDI);        /* set cursor */
  170.  
  171.     _rax = 0x900 + c;        /* AH=Fn#9, AL=char */
  172.     _rcx = 1;            /* CX=count */
  173.     _rbx = page*256 + current_attr;    /* BH=page, BL=attr */
  174.     _doint (VIDI);        /* write character */
  175. #endif
  176. }
  177.  
  178. hputc (c)
  179.   char    c;
  180. {
  181.     union REGS rr;
  182.  
  183.     rr.h.ah = 14;        /* TTY write function */
  184.     rr.h.al = c;
  185.     int86 (VIDI, &rr, &rr);
  186. }
  187.  
  188. hputs (s)
  189.   char    *s;
  190. {
  191.     char    *p;
  192.  
  193.     for (p=s; *p!='\0'; p++)
  194.         hputc (*p);
  195. }
  196.  
  197.  
  198. /*
  199.  *    This one switches us to a different page, without changing
  200.  *    the contents of that page.
  201.  */
  202.  
  203. swpage (newpage)
  204.     int     newpage;
  205. {
  206.     page = newpage;
  207.     _rax = 0x500 + page;        /* new page function */
  208.     _doint ( VIDI );    /* interrupt call */
  209. }
  210.  
  211.  
  212. scroll (top,left,bottom,right,size,attr)
  213.   int    top,left,bottom,right;
  214.   int    size,attr;
  215. {
  216.     union REGS rr;
  217.  
  218.     rr.h.ch = (char) top;
  219.     rr.h.cl = (char) left;
  220.     rr.h.dh = (char) bottom;
  221.     rr.h.dl = (char) right;
  222.     rr.h.bh = (char) attr;
  223.     if (size < 0) {        /* scroll down */
  224.         rr.h.al = -size;
  225.         rr.h.ah = 7;
  226.     }
  227.     else {            /* scroll up */
  228.         rr.h.al = size;
  229.         rr.h.ah = 6;
  230.     }
  231.  
  232.     int86 (0x10, &rr, &rr);
  233. }
  234.  
  235.  
  236.  
  237. waitkey ()
  238. {
  239.     _rax = 0;        /* keyboard blocking read function */
  240.     _doint (KBD);
  241. }
  242.